5. Devices

5.8 Floppy Disk

Power64 can simulate up to four Commodore 1541 single sided floppy disk drives on each simulated Commodore 64. You can use common *.D64 and the technically superior, but rarely used *.X64 file format as well as ZipCoded files (see Appendix C.3,  C.4 and C.5 for details on the file formats).

The original C1541 is a very intelligent device, that features its own MOS 6502 CPU, 16KByte of ROM, 2KByte RAM and some I/O circutry to control the floppy drive hardware. Most of the time the M6502 just sits idle and waits for a new command. When such a command comes some ROM code is executed and the M6502 sits idle again. It is rather inefficient to spend lots of Macintosh CPU time to fully simulate the M6502 on the other hand it is necessary for best compatibility.
Therefore Power64 offers two modes of Floppy emualtion: A ROM level emulation that is fast, but does not support some special tricks and a CPU level emulation that is extremly compatible, but this compatibility does of course include the original 1541 speed. To switch between these two modes of emulation use Devices/Disk Drive #x/Complete Floppy 1541 Emulation (Cmd-E).
To reduce the Macintosh CPU load, CPU level emulation is only available for the first two of the possible four drives (devices #8 and #9).

Using the ROM level disk emulation Power64 replaces the ROM routines of a 1541 with PowerPC code that display the same behaviour, but can be executed much faster. The supported ROM routines include both LOAD and SAVE for programs and access to sequential, relative and random access files. Power64 also supports all the common floppy commands, such as NEW, COPY, RENAME, SCRATCH, VALIDATE, INITIALIZE, POSITION, MEMORY-READ/WRITE, BLOCK-READ/WRITE, BUFFER-POINTER, BLOCK-ALLOCATE/FREE, U1, U2, UI and UJ. Only the commands MEMORY/BLOCK-EXECUTE are not supported, as these would require a the true emulation of the M6502. Of course there is also a channel for error messages.

The original Commodore 64 used a rather inefficient serial protocol to transfer data to and from the disk drive, and thus achieved a transfer rate of about 256 Byte/sec. In ROM level emulation mode Power64 does not emulate this protocol, but rather simulates the transfer at a byte level. Thus it achieves a speed of 250 KByte/sec making it possible to load a game without having to go for a coffee break. The drawback of this approach is that all programs that implement their own fast-loader routines will fail.
Most games will work using the ROM level disk emulation. Only if a game crashes in this mode or the error message 'COMMAND NOT EMULATED' appears in that disks directory window should you switch to Complete 1541 Floppy Emulation.

Using CPU level floppy emulation Power64 completely simulates the floppy disk drive. This makes it possible to run custom programs (such as fast loaders, copy protection or any program that wishes to use the extra CPU for parallel processing) on the floppys M6502 CPU or transmit data to the C64 using a custom protocol. While this gives a significant boost to compatibility, it unfortunatly also faithfully emulates the extended coffee breaks necessary for loading any larger program.

Beware: If you use the same disk simultaneously on several simulated Commodore 64, then each C64 will use its private copy of the disk. If you write a new file with one C64 it will not appear on the other C64. When both C64 write to the their copy of the disk, then the changes of that C64 whose window was closed first will be lost when the second C64 unmounts its tape. There is no concurrency control!

It is not yet possible to connect the Macintosh to a real 1541 disk drive. I would like to encourage dedicated Mac programmers and hardware freaks to try their skill on this problem.

5.9 Hard Disk

In addition to the regular C1541 floppy disk drive Power64 can use a folder of the Macintosh hard disk as a virtual disk drive for the C64. You can use both common file formats *.P00 and *.C64 (see Appendix C.1 and C.2 for details on the file format).

The hard disk is designed to mimic a C1541 floppy disk drive. You can LOAD and SAVE programs and view the directory. Yet it is obvious that a hard disk is technically quite different from a 1541. Therefore all tricks, that rely on details of the 1541 construction, such as block level access are not possible with a simulated hard disk. Even so it would technically be feasible the author has chosen not to implement any commands to copy, rename or delete files as this can easily be done using the Macintosh Finder. This can change with future versions of Power64.

5.10 Tape & Lynx Files in a Tape Drive

Power64 supports Tape Image Files in the common *.T64 and Lynx file format (see Appendix C.6/C.7 for details of the file formats). While the original Datasette tape drive used with the Commodore 64 was extremely slow (about 30 Byte/sec), the tape emulation is the fastest way to get a file into the emulated Commodore 64 (about 30 MByte/sec once the tape is mounted).

The tape emulation of Power64 supports both LOAD and SAVE for programs as well as readings and writing sequential data files. New files are  added at the end of the tape. If a file of that name already existed,  the old file is only overwritten if the duplicate *filenames on tapes  are not permitted in the Options/Device Option dialog. Otherwise two files with the same name coexist (just like on a real tape)

On an original Commodore 64 you need to press Play/Record to read/write data from/to a tape. This is done automatically by Power64 as soon as a tape is mounted.

There is also no need to rewind a tape. Whenever the end of tape has been reached Power64 will automatically rewind to the beginning.

If you are no longer sure what files are stored on a tape, you can use LOAD"$",1 to load the directory of the tape. This is a special feature of Power64 that is not found on a real Commodore 64. Power64 implements the directory as a special file that it dynamically creates at the end of the tape image. Thus when the emulated Commodore 64 searches for the file "$" it will first find all other files stored on the tape and print their names in order to inform you of the progress of the search. Thus you will in fact see the directory twice; once as the Commodore 64 reports the progress of its search, and once when you list the loaded file.

When the *.T64 file format was new, there was no documentation about its internal workings. This lead many programmers to guess what the file format might look like, and write their own converter tools. Unfortunately many of them made some errors which leads to the fact that many *.T64 files in circulation have an erroneous format. When Power64 detects such a file it will automatically fix the problem and display a dialog box informing you of the problem.

On a regular Commodore 64 the key combination Shift/Run could be used to simulate the key sequence "LOAD <Enter> RUN <Enter>" and load the first file on a tape. This will not always work in Power64. Power64 permits you to select a default device for LOAD and SAVE other than device 1 (the tape) (see 5.12 Disk & Tape Options for details). If the default device is set to a floppy disk (or hard disk), then typing LOAD will attempt to load from there, which in turn will report a missing filename error. To load the first file from a tape you will then need to type LOAD"",1. 

As mentioned above, the tape drive was extremely slow on the real C64. Therefore, there were many programs that used their private tape access code to accelerate loading from tape. As the simulation of the tape in Power64 is based on the system-ROM functions for tape access, these programs are likely to crash on Power64.

Beware: If you use the same tape simultaneously on several simulated Commodore 64, then each C64 will use its private copy of the tape. If you write a new file with one C64 it will not appear on the other C64. When both C64 write to the their copy of the tape, then the changes of that C64 whose window ws closed first will be lost when the second C64 unmounts its tape. There is no concurrency control!

It is not yet possible to connect the Macintosh to a real tape drive (e.g. via the audio input). I would like to encourage dedicated Mac programmers to try their skill on this problem.

5.11 Tape & Lynx Files in a Disk Drive

Power64 also offers the possibility to use *.T64 or Lynx files in a disk drive. While this might seem queer at a first glance, many games that  can be found in a Lynx file expect to be loaded from disk.

The tape disk is designed to mimic a C1541 floppy disk drive. You can LOAD and SAVE programs and view the directory. Even some of the basic 1541 Commands such as NEW, VALIDATE, SCRATCH, COPY or RENAME are availale when for T64 or Lynx files are mounted on a disk drive, making it a good platform for maintainance work. Yet it is obvious that a tape disk is quite different from a 1541, and therefore all tricks, that rely on details of the 1541 construction, such as block level access are not possible with a simulated tape disk.

5.12 Disk & Tape Options

Default Device for Load and Save:
On an original C64 the default mass storage device is the cassette tape drive (device #1). On the other hand, most games for emulators come in D64 disk format. Thus it can be advantageous, to choose a different device (e.g. the primary disk drive - device #8) as the default device. This eliminates the need to type the device number after every LOAD or SAVE statement.

Automatically Open Directory when...:
When a device is connected to Power64 it can automatically open a window to display the directory of the device. By double-clicking on a program it can automatically be loaded and/or run. See the next paragraph for details.
Note: Even when these options are not selected they can be enforced by holding down the Option-Key when attaching the device.

Double-Click on Directory executes:
Power64 can automatically load and run a game when the user clicks on the program file in the directory window. Choose if you want to load or load and run the game. Pressing the Option Key while double-clicking on a filename will always produce Load"File",8 no matter what option has been selected. Note: Power64 simulates the keypresses for the necessary commands. This will produce the desired effect if the emulated C64 waits for key input at the BASIC prompt. If a different program is already running when the user clicks on the filename, this program will receive and process the keyboard, possibly causing interesting effects.

Mount Harddisk on every New C64:
Power64 can mount a standard hard disk whenever it created a new C64 emulator window. This is makes it especially conveniant to load a game from a collection of
CBM/P00 games. It also gives every C64 application a drive to write data to.
If a hard disk is mounted on a new C64 Power64 can also automatically display the directory. This is independent from the Automaticall Open Directory when…  described above.
 
Intelligent Floppy 1541 Emulation:
Games that require a complete Floppy 1541 emulation usually do not use the floppy CPU all the time. Rather they load some data with their built in fastloaders and than the floppy sits idle again. Power64 can attempt to determine when the floppy  is idle and suspend the emulation for such times. While the algorithm, that determines when the floppy is unused is indeed quite smart, it is still possible to fool it with the correct piece of software, so it might be necessary to turn if off for certain games.
While the algorithm, that determines when the floppy is unused is indeed quite smart, it is still possible to fool it with the correct piece of software, so it might be necessary to turn if off for certain games.

All Files on a Tape are of Type 'PRG':
Unfortunatly many T64 games that are available from the internet are damaged. Power64 attempts to fix the file as good as possible. In particular Power64 has to guess the type of all files on the tape image. Use this feature to override Power64's logic and cause all files to be 'PRG'. This is by far the most common file type and therefore a good guess. While a file must be of type 'PRG' to load it by double clicking in the directory it is still possible to load a file of a different type by manually typing the required load command.

Show a Warning for Damaged T64 files: 
When Power64 mounts a damaged T64 file it can display a warning message to the user. Fortunatly Power64 features a rather intelligent repair algorithm that manages to fix almost all problems, so you if you consider this alert a nuisance rather than useful information you might as well turn it off.
 
Adjust Type/Creator to Power64:
Every file on the Macintosh has a Type and Creator. This information is used by the Finder to decide which application to launch when the user opens a document. If you mount a tape or disk  image that has no Type/Creator information, Power64 can add it. This is useful when the  you've downloaded lots of ZIP encoded files from the Internet that have no notion of Type/Creator and substitute useless information. On the other hand, it  is not proper Mac style to mess with the Type/Creator codes. Therefore, Power64 can be configured to add the information, ask first, or not do it at all. Power64 distinguishes between files that have been configured for Frodo (another C64 emulator available also for the Mac) and files that have not been configured for any known emulator.

Drive Status LEDs:
To keep an eye on the floppy disk (and hard disk) activity of a C64 select Devices/Drive Status LEDs (Cmd-L; Use Opt-Cmd-L to display the LEDs in all C64 windows). This will cause Power64 to display two symbols per enabled disk drive in the bottom left corner. The first symbols stands for the floppy LED. If it is off (gray) the floppy drive is idle. A green LED indicates a read access, a red LED a write access and a yellow LED stands of an open file without read or write activity. The second symbol indicates the floppy error status; a green check means Ok, a red cross indicates an error. 

5.13 Printer

Power64 supports up to two virtual printers per emulated C64. The data written to each C64 printer is not printed on the Macintosh printer, but redirected to a Macintosh file. From there it can easily be read into any Macintosh program for postprocessing, reading and possibly printing.

Power64 supports three printer modes:
In Text Only mode Power64 translates all printed characters from the CBM character set to the Macintosh character set. If no translation exists, the corresponding character is simply  dropped. In Text with Hex-Graphics mode Power64 substitutes those characters that represent graphic bitmaps by their hexadecimal number. In Binary mode, no translation takes place at all. A byte from the C64 is directly stored in the file.

The printer files are called 'C64 Printer - dd.mm.yyyy (x)' where dd.mm.yyyy is the current date and x is a counter. Click on Select Print-File Folder to choose the folder in which these files are to be stored.

To get better performance Power64 maintains internal buffers for the printer output. These buffers are flushed when the emulator window is closed. If you want to use the printer files without having to close the emulator window, use Devices/Reset Printer #x to flush these buffers at any time. Any new data sent to that printer will then be written to a new file.

5.14 System ROM Patches

Some features built into the system ROMs of the original Commodore 64 are not useful with an emulator or may not be to some peoples liking. Using the ROM Patches dialog (via the menu item Options/ROM Patches) you can adjust the following features:

Kernal ROM:
Over the years Commodore made minor changes to the C64 Kernal ROMs. There were three releases: Rev. A was built into the very early C64s. Rev. B was used in 1982/83. Rev. C was the final version. The only difference you might ever notice is the way the color RAM is erased when clearing the screen; Rev. A does no clear it at all, Rev. B set all characters to the background color and Rev. C sets everything to the cursor color.

FastReset (Skip RAM Test):
A real Commodore 64 executes thorough RAM test on power up and at every reset. This is used to find hardware RAM errors, and to determine to the amount of RAM available for BASIC. Unfortunately this test takes about 3 seconds. On an emulated Commodore 64 there is no need to check the RAM for errors as the Macintosh has already done so at its power up, and the amount of BASIC RAM is known a-priori, thus the RAM test can be skipped without any harm, saving the 3 seconds.

Honor Cartridge-ID on Reset:
The Commodore 64 ROM can be expanded by the use of ROM cartridges. This was used for games, as well as tools like Simon's BASIC. The cartridge ROM is mapped into the memory area $8000-$9FFF (8 KByte cartridge) or $8000-$BFFF (16 KByte).
During the reset routine the Commodore 64 checks for the magic string "CBM80" at the address $8004-$8008. If the magic string is present the Commodore 64 concludes that there is a cartridge present, (even so it might as well be the RAM that happens to contain these values) and performs a jump to ($8000). Thus the code in the cartridge always gets the chance to start its game or run whatever initialization the tool requires. On the other hand this feature can be used to write programs that can not be terminated even by reset. 
When the Honor Cartridge-ID on Reset box is check the emulator will check for the magic string just like on a real Commodore 64. If the box is not checked, the magic string will never be found (even if it is present in memory). Note that some games require that the string be found, thus it is not recommended to turn this feature off. To force a Hard-Reset it is possible to override the Honor Cartridge-ID on Reset using the Option-Key. If this key is pressed while the reset routine is executed the Cartridge ID will never be honored.

Honor Cartridge-ID on NMI (Non Maskable Interrupts):
The same magic string that enables the code in a cartridge to take over during reset (see above) also permits the cartridge to control the effect of NMIs. Thus the Restore key can be used for special purposes by the cartridge.
When the Honor Cartridge-ID on NMI box is check the emulator will check for the magic string just like on a real Commodore 64. If the box is not checked, the magic string will never be found (even if it is present in memory). Note that some games require that the string be found, thus it is not recommended to turn this feature off.

Enable Emulator Detection:
Wolfgang Lorenz developed a method that makes it possible for C64 software to determine whether it is running on a real Commodore 64 or an emulator. On a conforming emulator the value of $DFFF is either $55 or $AA and is toggled between these two values at every read access. For more details on this topic see the program 'Where Am I' listed in Appendix D. Checking the Emulator Detection box will make Power64 conform to the emulator detection standard.

Font ROM:
The C64 character set, as shipped in the C64 font ROM contains two 'bugs'; graphic characters (#101 ($65) and #103 ($67)), that are defined differently in the ROM that in the C64 documentation. Power64 can either use the original C64 fonts (offering maximal compatibility) or fix the font ROM (for accuracy to the paper specs).  
Either way, the C64 features a character set of rather bold characters. If you prefer a lighter character set, you can also select the VC20 fonts. Note that not only the characters, but also the graphic symbols are slimmer. This can cause some games, that employ character graphics, to look queer.

Default Colors: (Text / Background / Frame)
On a real Commodore 64 text is usually displayed in light blue on a dark blue screen surrounded by a light blue frame. Some people might disapprove of these colors, so there is a possibility to select a different set of default colors. Note that the Text and Background color must be different to produce a readable image.